package state

import "fmt"

// 定义状态
// 定义多个状态，为所处状态实现具体方法

type State interface {
	name() string
	addItem(int) error
	requestItem() error
	insertMoney(money int) error
	dispenseItem(count int) error
}
type NoItemState struct {
	vendingMachine *VendingMachine
}

func (i *NoItemState) requestItem() error {
	return fmt.Errorf("Item out of stock")
}
func (i *NoItemState) name() string {
	return "NoItemState"
}

func (i *NoItemState) addItem(count int) error {
	i.vendingMachine.incrementItemCount(count)
	i.vendingMachine.SetCurrentState(i.vendingMachine.hasItem)
	return nil
}

func (i *NoItemState) insertMoney(money int) error {
	return fmt.Errorf("Item out of stock")
}
func (i *NoItemState) dispenseItem(count int) error {
	return fmt.Errorf("Item out of stock")
}
